package com.efuture.androidmvpdemo.ui.main

import com.efuture.androidmvpdemo.net.ApiParameter
import com.efuture.androidmvpdemo.net.NetService
import com.efuture.netrequestdemo.bean.Project
import com.efuture.netrequestdemo.utils.AppUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**

 *@description:TODO
 * @author: zhaoshanshan
 * @date: 2022/3/26 6:57 下午

 */
class MainInteractor{

    interface MainListener{
        fun loadDataSuccess(projectData: Project)
        fun loadDataFail(reason:String)
    }
    fun loadData(mainScope:CoroutineScope, listener:MainListener){
        mainScope.launch(Dispatchers.Main) {
            val cid = "294"
            val projectData: Project? = NetService.request(ApiParameter.getProject(cid),"正在获取数据中...")
            if (null != projectData && projectData.errorCode == 0) {
                listener.loadDataSuccess(projectData)
            } else {
                listener.loadDataFail("获取主页数据失败")
            }
        }
    }
}
